
# -*- coding: UTF-8 -*-

import datetime
import hashlib
import random

from lj_tool import tool_json


def gen_id():
    return f"{datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')}{random.randint(1000, 9999)}"


def gen_id_str():
    return str(gen_id())


def gen_un_key(*args, **kwargs):
    identifier = ''
    for arg in args:
        if arg:
            identifier += tool_json.dumps(arg)
    for key, value in kwargs.items():
        identifier += tool_json.dumps({key: value})

    md5_hash = hashlib.md5()
    md5_hash.update(identifier.encode('utf-8'))
    return md5_hash.hexdigest()
